﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace stadt_verlangen
{
    class SpinGame
    {
        Texture2D[] sprites;
        KeyboardState keyboardState = Keyboard.GetState();
        KeyboardState previousKeyboardState;
        public float rotation;
        public int currentScore;
        public int highScore;
        SpriteFont gameFont;
        public bool want2quit;

        public SpinGame(Texture2D[] loadTexture,SpriteFont newGameFont,int oldHighScore) 
        {
            sprites = loadTexture;
            rotation = 0.0f;
            currentScore = 0;
            highScore = oldHighScore;
            gameFont = newGameFont;
            want2quit = false;
        }

        public void Update(GameTime gameTime) 
        {
            previousKeyboardState = keyboardState;
            keyboardState = Keyboard.GetState();

            if (keyboardState.IsKeyDown(Keys.Right)) 
            {
                rotation += 0.1f;
                if (rotation >= Math.PI * 2) 
                {
                    rotation = 0.0f;
                    currentScore++;
                }
            }
            else if (keyboardState.IsKeyDown(Keys.Left)) 
            {
                rotation -= 0.1f;
                if (rotation <= -Math.PI * 2) 
                {
                    rotation = 0.0f;
                    currentScore++;
                }
            }

            if (keyboardState.IsKeyDown(Keys.Escape)) 
            {
                want2quit = true;
            }

            if (currentScore > highScore) 
            {
                highScore = currentScore;
            }
        }

        public void Draw(SpriteBatch spriteBatch, GameTime gameTime) 
        {

            spriteBatch.Draw(sprites[0], new Vector2(512.0f, 384.0f), null, Color.White, 0.0f, new Vector2(sprites[0].Width / 2, sprites[0].Height / 2),1.0f, SpriteEffects.None, 0);

            spriteBatch.Draw(sprites[1], 
                new Vector2(512.0f, 384.0f),
                null,
                Color.White, 
                rotation, 
                new Vector2(sprites[1].Width / 2, sprites[1].Height / 2),
                1.0f,
                SpriteEffects.None, 
                0);

            spriteBatch.DrawString(gameFont,
                "Score: " + currentScore.ToString(),
                new Vector2(800.0f,50.0f),
                Color.Black);

            spriteBatch.DrawString(gameFont,
                "Highscore: " + highScore.ToString(),
                new Vector2(800.0f, 65.0f),
                Color.Black);

        }
    }
}
